package sistema.validador;
// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov  Date: 29/3/2006 21:06:19
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   Validator.java

import java.io.*;

public final class Validator extends ValidatorInitialSpace23
{

    private void setLogfile(String log)
    {
        logfile = log;
    }

    private String getLogfile()
    {
        return logfile;
    }

    private void usage()
    {
        VersionInfo vi = new VersionInfo();
        System.out.println("Usage: java Validator <inputfile name> <outputfile name> <answerfile name> <resultfile name> <-pc2> [options] icflag");
        System.out.println("\n WHERE OPTIONS INCLUDE: ");
        System.out.println("<difftype> or <XML FILE for diff configration>");
        System.out.println("icflag - ignore case flag during diff/compare (true or false)");
        System.out.println();
        System.out.println("diff types are: ");
        System.out.println("1 - diff");
        System.out.println("2 - ignore whitespace at start of file");
        System.out.println("3 - ignore leading whitespace on lines");
        System.out.println("4 - ignore all whitespace on lines");
        System.out.println("5 - ignore empty lines");
        System.out.println("6   2 & 3");
        System.out.println("7   2 & 4");
        System.out.println("8   2 & 5");
        System.out.println("9   3 & 5");
        System.out.println("10  4 & 5");
        System.out.println();
        System.out.println(vi.getSystemVersionInfo());
    }

    public static void main(String args[])
        throws Exception
    {
        if(args.length < 1)
        {
            (new Validator()).usage();
            System.exit(4);
        }
        if(args[0].equals("-help"))
        {
            (new Validator()).usage();
            System.exit(4);
        }
        try
        {
            if(args.length <= 4)
            {
                System.out.println("Too few parameters, use -help option for usage ");
                System.exit(4);
            } else
            {
                Validator valid = new Validator();
                if(args[3].indexOf(".") >= 0)
                    valid.setLogfile(args[3].substring(0, args[3].indexOf(".")) + ".log");
                else
                    valid.setLogfile(args[3] + ".log");
                String carriage = "false";
                try
                {
                    carriage = args[6].toLowerCase();
                }
                catch(Exception _ex)
                {
                    System.out.println("Missing or invalid ignore case flag. The validation will be performed with case sensitivity");
                }
                boolean ignoreCase = carriage.equalsIgnoreCase("true");
                ValidatorSpace vs = new ValidatorSpace();
                ValidatorCarriage vc = new ValidatorCarriage();
                ValidatorInitialSpace vis = new ValidatorInitialSpace();
                DiffIgnoreFileHeaderWhitespace difhws = new DiffIgnoreFileHeaderWhitespace();
                Diff diff = new Diff(vs, args[4]);
                DiffIgnoreSpaceCarriage disc = new DiffIgnoreSpaceCarriage();
                valid.invokeValidator(valid, vc, vs, vis, diff, disc, args, difhws, ignoreCase);
                switch(valid.statusDiff)
                {
                case -1: 
                    ((ValidatorSpace) (valid)).result.println("<?xml version=\"1.0\"?>");
                    ((ValidatorSpace) (valid)).result.println("<result outcome =  \"No - Indeterminant. \" security = \"" + args[3] + "\">" + valid.getDiffDescription() + "</result>");
                    break;

                case 0: // '\0'
                    if(valid.getChoice() != 10 && valid.diffflag)
                    {
                        valid.setChoice(-1);
                        valid.setchoiceflag = true;
                        valid.invokeValidator(valid, vc, vs, vis, diff, disc, args, difhws, ignoreCase);
                    }
                    if(valid.statusDiff == 1)
                    {
                        ((ValidatorSpace) (valid)).result.println("<?xml version=\"1.0\"?>");
                        ((ValidatorSpace) (valid)).result.println("<result outcome =  \"No - Presentation Error\" security = \"" + args[3] + "\">" + valid.getDiffDescription() + "</result>");
                        break;
                    }
                    if(valid.statusDiff == 0)
                    {
                        ((ValidatorSpace) (valid)).result.println("<?xml version=\"1.0\"?>");
                        ((ValidatorSpace) (valid)).result.println("<result outcome =  \"No - Wrong Answer\" security = \"" + args[3] + "\">" + valid.getDiffDescription() + "</result>");
                    } else
                    {
                        ((ValidatorSpace) (valid)).result.println("<?xml version=\"1.0\"?>");
                        ((ValidatorSpace) (valid)).result.println("<result outcome =  \"No - Indeterminant.\" security = \"" + args[3] + "\">" + valid.getDiffDescription() + "</result>");
                    }
                    break;

                case 1: // '\001'
                    ((ValidatorSpace) (valid)).result.println("<?xml version=\"1.0\"?>");
                    ((ValidatorSpace) (valid)).result.println("<result outcome =  \"Yes\" security = \"" + args[3] + "\">" + valid.getDiffDescription() + "</result>");
                    break;

                default:
                    ((ValidatorSpace) (valid)).result.println("<?xml version=\"1.0\"?>");
                    ((ValidatorSpace) (valid)).result.println("<result outcome =  \"No - Indeterminant.\" security = \"" + args[3] + "\">" + valid.getDiffDescription() + "</result>");
                    break;
                }
            }
        }
        catch(Exception ex)
        {
            System.err.println("Exception in Validator.main() " + ex.getMessage());
            ex.printStackTrace(System.err);
        }
    }

    public Validator()
    {
        setchoiceflag = false;
        securityKey = "23456&%$$";
        diffflag = true;
        choice = -1;
    }

    public int getChoice()
    {
        return choice;
    }

    public void setChoice(int newChoice)
    {
        choice = newChoice;
    }

    public void invokeValidator(Validator valid, ValidatorCarriage vc, ValidatorSpace vs, ValidatorInitialSpace vis, Diff diff, DiffIgnoreSpaceCarriage disc, String args[], 
            DiffIgnoreFileHeaderWhitespace difhws, boolean ignoreCase)
    {
        if(args.length > 5 && !valid.setchoiceflag)
            valid.setChoice(Integer.parseInt(args[5]));
        if(args.length >= 5)
        {
            String out_filename = args[1];
            String answer_filename = args[2];
            String result_filename = args[3];
            if("-pc2".equals(args[4].toLowerCase()) && vs.isGlobalValidator())
            {
                switch(choice)
                {
                case 1: // '\001'
                    diffflag = false;
                    valid.Createfiles(out_filename, valid.getLogfile(), answer_filename, result_filename);
                    if(ignoreCase)
                        valid.statusDiff = diff.diffoneIgnoreCase(out_filename, answer_filename, ((ValidatorSpace) (valid)).log);
                    else
                        valid.statusDiff = diff.diffone(out_filename, answer_filename, ((ValidatorSpace) (valid)).log);
                    ((ValidatorSpace) (valid)).log.println("Status diff " + valid.statusDiff);
                    break;

                case 2: // '\002'
                    try
                    {
                        valid.Createfiles(out_filename, valid.getLogfile(), answer_filename, result_filename);
                        valid.diffIniWhiteSp(((ValidatorSpace) (valid)).input, "temp1.txt", ((ValidatorSpace) (valid)).log);
                        valid.diffIniWhiteSp(((ValidatorSpace) (valid)).answer, "temp2.txt", ((ValidatorSpace) (valid)).log);
                        if(ignoreCase)
                            valid.statusDiff = diff.diffone("temp1.txt", "temp2.txt", ((ValidatorSpace) (valid)).log);
                        else
                            valid.statusDiff = diff.diffone("temp1.txt", "temp2.txt", ((ValidatorSpace) (valid)).log);
                        ((ValidatorSpace) (valid)).log.println("Status diff " + valid.statusDiff);
                    }
                    catch(IOException ex)
                    {
                        ((ValidatorSpace) (valid)).log.println("Exception in Diffspace " + ex);
                    }
                    break;

                case 3: // '\003'
                    try
                    {
                        valid.Createfiles(out_filename, valid.getLogfile(), answer_filename, result_filename);
                        vis.diffIniSp(((ValidatorSpace) (valid)).input, "temp1.txt", ((ValidatorSpace) (valid)).log);
                        vis.diffIniSp(((ValidatorSpace) (valid)).answer, "temp2.txt", ((ValidatorSpace) (valid)).log);
                        if(ignoreCase)
                            valid.statusDiff = diff.diffoneIgnoreCase("temp1.txt", "temp2.txt", ((ValidatorSpace) (valid)).log);
                        else
                            valid.statusDiff = diff.diffone("temp1.txt", "temp2.txt", ((ValidatorSpace) (valid)).log);
                        ((ValidatorSpace) (valid)).log.println("Status diff " + valid.statusDiff);
                    }
                    catch(IOException ex)
                    {
                        ((ValidatorSpace) (valid)).log.println("Exception in Diffspace " + ex);
                    }
                    break;

                case 4: // '\004'
                    try
                    {
                        valid.Createfiles(out_filename, logfile, answer_filename, result_filename);
                        vs.diffSp(((ValidatorSpace) (valid)).input, "temp1.txt", ((ValidatorSpace) (valid)).log);
                        vs.diffSp(((ValidatorSpace) (valid)).answer, "temp2.txt", ((ValidatorSpace) (valid)).log);
                        if(ignoreCase)
                            valid.statusDiff = diff.diffoneIgnoreCase("temp1.txt", "temp2.txt", ((ValidatorSpace) (valid)).log);
                        else
                            valid.statusDiff = diff.diffone("temp1.txt", "temp2.txt", ((ValidatorSpace) (valid)).log);
                        ((ValidatorSpace) (valid)).log.println("Status diff " + valid.statusDiff);
                    }
                    catch(IOException ex)
                    {
                        ((ValidatorSpace) (valid)).log.println("Exception in Diffspace " + ex);
                    }
                    break;

                case 5: // '\005'
                    try
                    {
                        valid.Createfiles(out_filename, valid.getLogfile(), answer_filename, result_filename);
                        vc.diffCar(((ValidatorSpace) (valid)).input, "temp1.txt", ((ValidatorSpace) (valid)).log);
                        vc.diffCar(((ValidatorSpace) (valid)).answer, "temp2.txt", ((ValidatorSpace) (valid)).log);
                        if(ignoreCase)
                            valid.statusDiff = diff.diffoneIgnoreCase("temp1.txt", "temp2.txt", ((ValidatorSpace) (valid)).log);
                        else
                            valid.statusDiff = diff.diffone("temp1.txt", "temp2.txt", ((ValidatorSpace) (valid)).log);
                        ((ValidatorSpace) (valid)).log.println("Status diff " + valid.statusDiff);
                    }
                    catch(IOException ex)
                    {
                        ((ValidatorSpace) (valid)).log.println("Exception in Diffspace " + ex);
                    }
                    break;

                case 6: // '\006'
                    try
                    {
                        new ValidatorInitialSpace23();
                        valid.Createfiles(out_filename, valid.getLogfile(), answer_filename, result_filename);
                        valid.diffIniSp23(((ValidatorSpace) (valid)).input, "temp1.txt", ((ValidatorSpace) (valid)).log);
                        valid.diffIniSp23(((ValidatorSpace) (valid)).answer, "temp2.txt", ((ValidatorSpace) (valid)).log);
                        ((ValidatorSpace) (valid)).input.close();
                        ((ValidatorSpace) (valid)).answer.close();
                        ((ValidatorSpace) (valid)).tempans.close();
                        if(ignoreCase)
                            valid.statusDiff = diff.diffoneIgnoreCase("temp1.txt", "temp2.txt", ((ValidatorSpace) (valid)).log);
                        else
                            valid.statusDiff = diff.diffone("temp1.txt", "temp2.txt", ((ValidatorSpace) (valid)).log);
                        ((ValidatorSpace) (valid)).log.println("Status diff " + valid.statusDiff);
                    }
                    catch(IOException ex)
                    {
                        ((ValidatorSpace) (valid)).log.println("Exception in Diffspace " + ex);
                    }
                    break;

                case 7: // '\007'
                    try
                    {
                        valid.Createfiles(out_filename, valid.getLogfile(), answer_filename, result_filename);
                        difhws.diffIniWhiteSp(((ValidatorSpace) (valid)).input, "temp1.txt", ((ValidatorSpace) (valid)).log);
                        difhws.diffIniWhiteSp(((ValidatorSpace) (valid)).answer, "temp2.txt", ((ValidatorSpace) (valid)).log);
                        ((ValidatorSpace) (valid)).input.close();
                        ((ValidatorSpace) (valid)).answer.close();
                        ((ValidatorSpace) (valid)).tempans.close();
                        FileReader inputtemp = new FileReader("temp1.txt");
                        FileReader answertemp = new FileReader("temp2.txt");
                        vs.diffSp(inputtemp, "inputTEMP1.txt", ((ValidatorSpace) (valid)).log);
                        vs.diffSp(answertemp, "inputTEMP2.txt", ((ValidatorSpace) (valid)).log);
                        if(ignoreCase)
                            valid.statusDiff = diff.diffoneIgnoreCase("inputTEMP1.txt", "inputTEMP2.txt", ((ValidatorSpace) (valid)).log);
                        else
                            valid.statusDiff = diff.diffone("inputTEMP1.txt", "inputTEMP2.txt", ((ValidatorSpace) (valid)).log);
                        ((ValidatorSpace) (valid)).log.println("Status diff " + valid.statusDiff);
                    }
                    catch(IOException ex)
                    {
                        ((ValidatorSpace) (valid)).log.println("Exception in Diffspace " + ex);
                    }
                    break;

                case 8: // '\b'
                    try
                    {
                        valid.Createfiles(out_filename, valid.getLogfile(), answer_filename, result_filename);
                        difhws.diffIniWhiteSp(((ValidatorSpace) (valid)).input, "temp1.txt", ((ValidatorSpace) (valid)).log);
                        difhws.diffIniWhiteSp(((ValidatorSpace) (valid)).answer, "temp2.txt", ((ValidatorSpace) (valid)).log);
                        ((ValidatorSpace) (valid)).input.close();
                        ((ValidatorSpace) (valid)).answer.close();
                        FileReader inputtemp = new FileReader("temp1.txt");
                        FileReader answertemp = new FileReader("temp2.txt");
                        vc.diffCar(inputtemp, "inputTEMP1.txt", ((ValidatorSpace) (valid)).log);
                        vc.diffCar(answertemp, "inputTEMP2.txt", ((ValidatorSpace) (valid)).log);
                        if(ignoreCase)
                            valid.statusDiff = diff.diffoneIgnoreCase("inputTEMP1.txt", "inputTEMP2.txt", ((ValidatorSpace) (valid)).log);
                        else
                            valid.statusDiff = diff.diffone("inputTEMP1.txt", "inputTEMP2.txt", ((ValidatorSpace) (valid)).log);
                        ((ValidatorSpace) (valid)).log.println("Status diff " + valid.statusDiff);
                    }
                    catch(IOException ex)
                    {
                        ((ValidatorSpace) (valid)).log.println("Exception in Diffspace " + ex);
                    }
                    break;

                case 9: // '\t'
                    try
                    {
                        valid.Createfiles(out_filename, valid.getLogfile(), answer_filename, result_filename);
                        vis.diffIniSp(((ValidatorSpace) (valid)).input, "temp1.txt", ((ValidatorSpace) (valid)).log);
                        vis.diffIniSp(((ValidatorSpace) (valid)).answer, "temp2.txt", ((ValidatorSpace) (valid)).log);
                        ((ValidatorSpace) (valid)).input.close();
                        ((ValidatorSpace) (valid)).answer.close();
                        FileReader inputtemp = new FileReader("temp1.txt");
                        FileReader answertemp = new FileReader("temp2.txt");
                        vc.diffCar(inputtemp, "inputTEMP1.txt", ((ValidatorSpace) (valid)).log);
                        vc.diffCar(answertemp, "inputTEMP2.txt", ((ValidatorSpace) (valid)).log);
                        if(ignoreCase)
                            valid.statusDiff = diff.diffoneIgnoreCase("inputTEMP1.txt", "inputTEMP2.txt", ((ValidatorSpace) (valid)).log);
                        else
                            valid.statusDiff = diff.diffone("inputTEMP1.txt", "inputTEMP2.txt", ((ValidatorSpace) (valid)).log);
                        ((ValidatorSpace) (valid)).log.println("Status diff " + valid.statusDiff);
                    }
                    catch(IOException ex)
                    {
                        ((ValidatorSpace) (valid)).log.println("Exception in Diffspace " + ex);
                    }
                    break;

                case 10: // '\n'
                    try
                    {
                        valid.Createfiles(out_filename, valid.getLogfile(), answer_filename, result_filename);
                        vc.diffCar(((ValidatorSpace) (valid)).input, "temp1.txt", ((ValidatorSpace) (valid)).log);
                        vc.diffCar(((ValidatorSpace) (valid)).answer, "temp2.txt", ((ValidatorSpace) (valid)).log);
                        ((ValidatorSpace) (valid)).input.close();
                        ((ValidatorSpace) (valid)).answer.close();
                        FileReader inputtemp = new FileReader("temp1.txt");
                        FileReader answertemp = new FileReader("temp2.txt");
                        vc.diffCar(inputtemp, "inputTEMP1.txt", ((ValidatorSpace) (valid)).log);
                        vc.diffCar(answertemp, "inputTEMP2.txt", ((ValidatorSpace) (valid)).log);
                        if(ignoreCase)
                            valid.statusDiff = diff.diffoneIgnoreCase("inputTEMP1.txt", "inputTEMP2.txt", ((ValidatorSpace) (valid)).log);
                        else
                            valid.statusDiff = diff.diffone("inputTEMP1.txt", "inputTEMP2.txt", ((ValidatorSpace) (valid)).log);
                        ((ValidatorSpace) (valid)).log.println("Status diff " + valid.statusDiff);
                    }
                    catch(IOException ex)
                    {
                        ((ValidatorSpace) (valid)).log.println("Exception in Diffspace " + ex);
                    }
                    break;

                default:
                    valid.Createfiles(out_filename, valid.getLogfile(), answer_filename, result_filename);
                    valid.statusDiff = diff.diffone(out_filename, answer_filename, ((ValidatorSpace) (valid)).log);
                    ((ValidatorSpace) (valid)).log.println("Status diff " + valid.statusDiff);
                    break;
                }
            } else
            {
                System.out.println("Invalid parameter found, expecting -pc2 ");
                System.out.println("See usage for more details ");
                System.exit(4);
            }
        } else
        {
            System.out.println("Please reinvoke the Validator using the standard format. ");
            System.out.println("See usage for details");
        }
    }

    int statusDiff;
    public boolean setchoiceflag;
    public String securityKey;
    public boolean diffflag;
    private String logfile;
    public int choice;
    static final String TEMP1 = "temp1.txt";
    static final String TEMP2 = "temp2.txt";
    static final int VRESULT_CORRECT = 1;
    static final int VRESULT_FAILURE = 0;
    static final int VRESULT_INDETERMINANT = -1;
    static final int VRESULT_PRESENTATION_ERROR = 1;
    static final int VRESULT_WRONGANSWER = 0;
}